package com.sanploy.manage.controller;


import com.sanploy.common.domain.Banner;
import com.sanploy.common.domain.dto.BannerDto;
import com.sanploy.manage.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by zhu yingzhi on 2017/9/6.
 * @author yingzhi zhu
 * 后台轮播图接口 请求路由类
 */
@RestController
@RequestMapping("/banner")
public class BannerController
{
    @Autowired
    private BannerService bannerService;

    /**
     * 添加 Banner
     * @param bannerDto 数据传输对象
     * @return
     */
    @PostMapping(value = "")
    public Object addBanner(BannerDto bannerDto){
        return bannerService.addBanner(bannerDto);
    }

    /**
     * 编辑 Banner
     * @param banner 数据传输对象
     * @return
     */
    @PostMapping(value = "/{id}")
    public Object editBanner(Banner banner){
        return bannerService.editBanner(banner);
    }

    /**
     * 获取所有的Banner
     * @return
     */
    @GetMapping(value = "")
    public Object getAllBanner(){
        return bannerService.findAllBanner();
    }

    /**
     * 获取某个id
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}")
    public Object getAllBanner(@PathVariable Long id){
        return bannerService.findById(id);
    }


    /**
     * 通过删除轮播图
     * @param id 轮播图Id
     * @return
     */
    @GetMapping(value = "/delete/{id}")
    public Object deleteBanner(@PathVariable Long id){
        return bannerService.deleteBanner(id);
    }
}
